//
//  SpriteUtil.cpp
//  DiceWar
//
//  Created by Xiao  Feng on 17/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include "SpriteUtil.h"
#include "GameUtil.h"

USING_NS_CC;

namespace SpriteUtil 
{
    cocos2d::CCSprite* createSprite(const char* filePath, const cocos2d::CCPoint& position)
    {
        CCAssert(filePath, "The file path of the image is NULL!");
        
        CCSprite* pSprite = CCSprite::spriteWithFile(filePath);
        if (!pSprite) return NULL;
        
        pSprite->setPosition(position);
        return pSprite;
    }
    
    CCSprite* createSprite(const char* filePath, const CCPoint& position, const CCSize& relativeSizeToScreen)
    {
        CCSprite* pSprite = createSprite(filePath, position);
        if (!pSprite) return NULL;
        
        const CCSize kWinSize = GameUtil::getWindowSize();
        const CCSize kSpriteSize = pSprite->getContentSize();
        const float kScaleX = kWinSize.width * relativeSizeToScreen.width / kSpriteSize.width;
        const float kScaleY = kWinSize.height * relativeSizeToScreen.height / kSpriteSize.height;
        pSprite->setScaleX(kScaleX);
        pSprite->setScaleY(kScaleY);
        
        return pSprite;
    }
    

}
